package com.momoc.multi.chat.room.common.config;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.momoc.netty.frame.config.SmartNettyProperties;
import org.springframework.stereotype.Component;

@Component
public class CustomIdGenerator implements IdentifierGenerator {


    private SnowFlake idWorker;

    public CustomIdGenerator(SmartNettyProperties machine) {
        idWorker = new SnowFlake(Long.parseLong(machine.getDataCenterId()), Long.parseLong(machine.getMachineId()));
    }

    @Override
    public Long nextId(Object entity) {
        return idWorker.nextId();
    }
}
